package com.example.demo;

import com.alibaba.fastjson.JSON;
import com.example.demo.map.RaiseActivityTask;
import com.example.demo.map.ScoutAnchorActivityDateDTO;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;

public class test {

    public static void main(String[] args) {

        String name = "23131231【更多海量资源_666java.com】";
        String newName = name.replace("【更多海量资源_666java.com】", "");
        System.out.println(newName);

        String[] split = ",12,邀请者头像路径11".split(",");
        System.out.println(split);


        BigDecimal bigDecimal = new BigDecimal("77.88");
        BigDecimal bigDecimal1 = new BigDecimal("73.68");
        System.out.println(bigDecimal.subtract(bigDecimal1));


        Integer i = 8800;
        Integer i2 = 8820;
        Integer i3 = 8860;
        Integer i4 = 8846;
        Integer i5 = 30;
        Integer i6 = 60;

        // 向下取整
        //System.out.println(i/100);
        System.out.println(i2/100);
        System.out.println(i3/100);
        System.out.println(i4/100);
        System.out.println(i5/100);
        System.out.println(i6/100);

        Long aLong = i2 / 100L;
        System.out.println(aLong);
        System.out.println(Long.valueOf(i3/100));
        System.out.println(Long.valueOf(i6/100));

        // 向下取整
        System.out.println((i/100)*100);
        System.out.println((i2/100)*100);
        System.out.println((i3/100)*100);
        System.out.println((i4/100)*100);
        System.out.println((i5/100)*100);
        System.out.println((i6/100)*100);



        Map<String, Object> param = new HashMap<>();
        param.put("touser", "2313213");
        param.put("msgtype", "rr");
        param.put("agentid", 111);
        Map<String, Object> param1 = new HashMap<>();
        param1.put("content", "用户回访提醒\n用户昵称：张三\n订单号：12343535455454\n购买商品：xx衣服、xx鞋子\n实付金额：232.3");
        param.put("text", param1);

        System.out.println(JSON.toJSONString(param));


        LocalDateTime date = LocalDateTime.now().minusMonths(2);
        LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
        LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX);

        LocalDateTime lastDay1 = date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX);


        Date date1 = getPassMonthDate(new Date(), 2);
        Date date2 = getPassMonthDate(new Date(), 2);

        List<String> list = new ArrayList<>();
        list.add("aa");
        list.add("b");
        list.add("v");
        list.add("f");
        list.add("f");

        String u = "a";

        if (list.contains(u)) {
            System.out.println("符合");
        }

        for (String s : list) {
            if (s.equals(u)) {
                System.out.println("符合");
            }
        }


        LocalDateTime date3 = LocalDateTime.now().minusMonths(2);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
        String format = dateTimeFormatter.format(date3);
        System.out.println(format);

        //int abcabcbb = lengthOfLongestSubstring("abcabcbb");
        //System.out.println(abcabcbb);

        int[] nums1 = {1,3};
        int[] nums2 = {2};
        double arrays = findMedianSortedArrays(nums1, nums2);
        System.out.println(arrays);


        /*for (int binCount = 0; ; ++binCount) {
            System.out.println(binCount);
            System.out.println("jj");
            System.out.println(binCount);
        }*/

        System.out.println(getPassMonthDate(new Date(), 1));


    }
    /**
     * 获取任意时间的上n个月的第一天
     */
    public static Date getPassMonthDate(Date date, int n) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - n);
        return calendar.getTime();
    }

    public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int i = null != nums1 ? nums1.length : 0;
        int j = null != nums2 ? nums2.length : 0;
        if (j == 0 && i == 0) {
            return 0;
        }
        List<Integer> list = new ArrayList<>();
        if (i != 0) {
            list.addAll(Arrays.stream(nums1).boxed().collect(Collectors.toList()));
        }
        if (j != 0) {
            list.addAll(Arrays.stream(nums2).boxed().collect(Collectors.toList()));
        }
        List<Integer> collect = list.stream().sorted().collect(Collectors.toList());
        int i1 = collect.size() / 2;
        int i2 = collect.size() % 2;

        if (i2 != 0) {
            return collect.get(i1);
        }else {
            return (collect.get(i1) + collect.get(i1-1)) / 2.0;
        }
    }

    @Test
    public void tt() {
        List<RaiseActivityTask> list = new ArrayList<>();
        RaiseActivityTask task = new RaiseActivityTask();
        task.setTaskId(111l);
        task.setBrowseTime(1231);
        list.add(task);

        task = new RaiseActivityTask();
        task.setTaskId(2111l);
        task.setBrowseTime(21231);
        list.add(task);

        Map<String,List<RaiseActivityTask>> scoutGroup= list.stream().collect(Collectors.groupingBy(dto->{
            return dto.getTaskId() + "_" + dto.getBrowseTime();
        }));

        List<RaiseActivityTask> tasks = scoutGroup.get("111_1231");
        tasks.get(0).setMoneyMax(new BigDecimal("23123"));

        task = new RaiseActivityTask();
        task.setTaskId(32111l);
        task.setBrowseTime(221231);
        list.add(task);

        List<RaiseActivityTask> tasks2 = scoutGroup.get("111_1231");
        tasks2.get(0).setMoneyMax(new BigDecimal("23123213123"));

        scoutGroup= list.stream().collect(Collectors.groupingBy(dto->{
            return dto.getTaskId() + "_" + dto.getBrowseTime();
        }));


        ScoutAnchorActivityDateDTO dto = new ScoutAnchorActivityDateDTO();
        dto.setAfterTime(LocalDateTime.now());
        dto.setCurTime(LocalDateTime.now());

        String a = null;
        String ab = "dasd";

        if (ab.equals(a)) {
            System.out.println(232);
        }

        if (a.equals(ab)) {
            System.out.println(232);
        }
    }
}
